<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div {
        position: absolute;
        top: 100px;
        left: 100px;
        width: 100px;
        height: 100px;
        background-color: pink;
    }
</style>
<body>
    <div></div>
    <script>
        var div = document.querySelector('div');
        var starX = 0;
        var starY = 0;
        var x= 0;
        var y = 0;
        div.addEventListener('touchstart', function(e) {
            // 获取手初始坐标
            starX = e.targetTouches[0].pageX;
            starY = e.targetTouches[0].pageY;
            x = this.offsetLeft;
            y = this.offsetTop;
        });
        div.addEventListener('touchmove', function(e) {
             var moveX = e.targetTouches[0].pageX - starX ;
             var moveY = e.targetTouches[0].pageY - starY;
             this.style.left = x + moveX + 'px';
            this.style.top = y + moveY + 'px';
            e.preventDefault(); //阻止屏幕滚动的默认行为
        });
    </script>
</body>
</html>